package com.lingdian.busapp.common;

import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

import android.app.Activity;

public class CommonService {

	private BaseActivity activity;
	private String baseUrl = Host.domain;
	
	public CommonService(BaseActivity activity) {
		super();
		this.activity = activity;
	}
	public CommonService setTag(String tag){
		this.activity.setTag(tag) ;
		return this;
	}

	public void get(String url){
		HttpUtils httpUtils = new HttpUtils();
		if(url.startsWith("/")){
			url = url.replaceFirst("/", "");
		}
		url =baseUrl+ url;
		httpUtils.send(HttpMethod.GET, url, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				activity.processFailure(arg0, arg1);
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				activity.processSuccess(arg0);
			}
		});
	}
	
}
